<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">

        <p-row>
		  <p-col  :span="8">
			<p-form-item label="来源类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['sourceType', validatorRules.sourceType]" :trigger-change="true" dictCode="mes_quality_improve_task_source_type" placeholder="请选择来源类型"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="问题描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'questionExplain', validatorRules.questionExplain]" placeholder="请输入问题描述"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="责任部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-select-depart v-decorator="['dutyDepartment', validatorRules.dutyDepartment]" :trigger-change="true"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="回复日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择回复日期" v-decorator="[ 'replyDate', validatorRules.replyDate]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="回复超期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'replyOverdue', validatorRules.replyOverdue]" placeholder="请输入回复超期" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="处理周期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'processingCycle', validatorRules.processingCycle]" placeholder="请输入处理周期" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="附件url" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'annexUrl', validatorRules.annexUrl]" placeholder="请输入附件url"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="提出人" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'introducer', validatorRules.introducer]" placeholder="请输入提出人"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="产品编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['mcode', validatorRules.mcode]"
						:trigger-change="true"
						org-fields="mcode,mname"
						dest-fields="mcode,mname"
						code="mes_cpinfo_select"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'mname', validatorRules.mname]" placeholder="请输入产品名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="二级工序" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'process2', validatorRules.process2]" placeholder="请输入二级工序"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="要求报告回复时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择要求报告回复时间" v-decorator="[ 'nrpReplytime', validatorRules.nrpReplytime]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="处理人" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-select-user-by-dep v-decorator="['handler', validatorRules.handler]" :trigger-change="true"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="处理时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择处理时间" v-decorator="[ 'handleTime', validatorRules.handleTime]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="检验单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'inspectBillno', validatorRules.inspectBillno]" placeholder="请输入检验单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="改善报告附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'creportUrl', validatorRules.creportUrl]" placeholder="请输入改善报告附件"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="改善措施简述" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'cmeasureExplain', validatorRules.cmeasureExplain]" placeholder="请输入改善措施简述"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="措施预计完成时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择措施预计完成时间" v-decorator="[ 'measureYeTime', validatorRules.measureYeTime]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="当前处理人" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-select-user-by-dep v-decorator="['currentHandler', validatorRules.currentHandler]" :trigger-change="true"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="审核时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择审核时间" v-decorator="[ 'reviewTime', validatorRules.reviewTime]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="是否可结案" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="radio" v-decorator="['isCloseFile', validatorRules.isCloseFile]" :trigger-change="true" dictCode="ba_yn" placeholder="请选择是否可结案"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="措施完成情况说明" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mefConditionRemark', validatorRules.mefConditionRemark]" placeholder="请输入措施完成情况说明"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="验证时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择验证时间" v-decorator="[ 'checkTime', validatorRules.checkTime]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesQcQualityImproveTaskModal",
    mixins: [SubmitOnchangMixin],
    components: {
      JDate,
      JSelectDepart,
      JSelectUserByDep,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 1200,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          sourceType: {rules: [
            {required: true, message: '请输入来源类型!'},
          ]},
          questionExplain: {rules: [
            {required: true, message: '请输入问题描述!'},
          ]},
          dutyDepartment: {rules: [
            {required: true, message: '请输入责任部门!'},
          ]},
          replyDate: {rules: [
            {required: true, message: '请输入回复日期!'},
          ]},
          replyOverdue: {rules: [
            {pattern:/^-?\d+$/, message: '请输入整数!'},
          ]},
          processingCycle: {rules: [
            {required: true, message: '请输入处理周期!'},
          ]},
          annexUrl: {rules: [
            {required: true, message: '请输入附件url!'},
          ]},
          introducer: {rules: [
            {required: true, message: '请输入提出人!'},
          ]},
          mcode: {rules: [
            {required: true, message: '请输入产品编号!'},
          ]},
          mname: {rules: [
            {required: true, message: '请输入产品名称!'},
          ]},
          process2: {rules: [
            {required: true, message: '请输入二级工序!'},
          ]},
          nrpReplytime: {rules: [
            {required: true, message: '请输入要求报告回复时间!'},
          ]},
          handler: {rules: [
            {required: true, message: '请输入处理人!'},
          ]},
          handleTime: {rules: [
            {required: true, message: '请输入处理时间!'},
          ]},
          inspectBillno: {rules: [
            {required: true, message: '请输入检验单号!'},
          ]},
          creportUrl: {rules: [
            {required: true, message: '请输入改善报告附件!'},
          ]},
          cmeasureExplain: {rules: [
            {required: true, message: '请输入改善措施简述!'},
          ]},
          measureYeTime: {rules: [
            {required: true, message: '请输入措施预计完成时间!'},
          ]},
          currentHandler: {rules: [
            {required: true, message: '请输入当前处理人!'},
          ]},
          reviewTime: {rules: [
            {required: true, message: '请输入审核时间!'},
          ]},
          isCloseFile: {rules: [
            {required: true, message: '请输入是否可结案!'},
          ]},
          mefConditionRemark: {rules: [
            {required: true, message: '请输入措施完成情况说明!'},
          ]},
          checkTime: {rules: [
            {required: true, message: '请输入验证时间!'},
          ]},
        },
        url: {
          add: '/mes-quality/mesQcQualityImproveTask/add',
          edit: '/mes-quality/mesQcQualityImproveTask/edit',
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },

      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createTime','taskBillno','sourceType','questionExplain','dutyDepartment','replyDate','replyOverdue','processingCycle','taskStatus','annexUrl','introducer','mcode','mname','process2','nrpReplytime','handler','handleTime','inspectBillno','creportUrl','cmeasureExplain','measureYeTime','currentHandler','reviewTime','isCloseFile','mefConditionRemark','checkTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
              that.confirmLoading = true;
              let httpurl = '';
              let method = '';
              let formData = Object.assign(this.model, values);
              this.formData = Object.assign(this.model, values);
              //新增触发
              if(!this.model.id){
                httpurl+=this.url.add;
                method = 'post';
                if(this.EnhanceJS.afterAdd){
                  //新增之前
                  let Obj = eval(this.EnhanceJS.afterAdd)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }else{
                //编辑触发
                httpurl+=this.url.edit;
                method = 'put';
                if(this.EnhanceJS.afterEdit){
                 //编辑之前
                  let Obj = eval(this.EnhanceJS.afterEdit)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createTime','taskBillno','sourceType','questionExplain','dutyDepartment','replyDate','replyOverdue','processingCycle','taskStatus','annexUrl','introducer','mcode','mname','process2','nrpReplytime','handler','handleTime','inspectBillno','creportUrl','cmeasureExplain','measureYeTime','currentHandler','reviewTime','isCloseFile','mefConditionRemark','checkTime'))
      },


    }
  }
</script>
